﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="Microsoft.Web.Mvc"%>
<asp:Content ID="indexHead" ContentPlaceHolderID="head" runat="server">
    <title>Search</title>
</asp:Content>

<asp:Content ID="indexContentLeft" ContentPlaceHolderID="left_content" runat="server">
           <div class="title"><span class="title_icon"><img src="/content/images/bullet1.gif" alt="" title="" /></span>Tìm Kiếm Nâng Cao</div>
        
        	<div class="feat_prod_box_details">
        	    <form action="/book/search" method="get" id="search">
              	  <div class="contact_form">
                    <div class="form_row">
                    <label class="contact"><strong>Từ khoá (*):</strong></label>
                    <input maxlength="32" id="title" name="title" type="text" class="contact_input" value="<%=ViewData["title"] %>" />
                    </div>  

                    <div class="form_row">
                    <label class="contact"><strong>Từ khoá phụ :</strong></label>
                        <input maxlength="32" name="content" type="text" class="contact_input" value="<%=ViewData["content"] %>" />
                        <div style="margin-left:80px;">
					        <input type="radio" name="option" value="1" <% if(Convert.ToInt32(ViewData["option"])==1){ %> checked="checked"<% } %> /> Trong mô tả sách &nbsp;&nbsp;
					        <input type="radio" name="option" value="2" <% if(Convert.ToInt32(ViewData["option"])==2){ %> checked="checked"<% } %> /> Trong tên tác giả<br>
					    </div>
                    </div>
                    
                    <div class="form_row">
                    <label class="contact"><strong>Danh mục :</strong></label>
					<select name="category" style="color:#999 !important;">
					    <option value="-1">Tất cả</option>
					 <% string[][] category = (string[][])ViewData["category"]; %>
	                    <% if (category != null && category.Length > 0)  {%>
                       <% foreach (string[] row in category)  { %>
                         <% if (row != null) {%>  
                         <option <% if(Convert.ToInt32(ViewData["category_id"])== Convert.ToInt32(row[0]) ){ %> selected="selected"<% } %> value="<%= row[0] %>"><%= row[1] %></option>     
                         <%}  }  } %>
					</select>
                    </div>


                    <div class="form_row">
                    <label class="contact"><strong>Giá mua từ :</strong></label>
                    <input value="<%=ViewData["price_from"] %>" id="price_from" name="price_from" maxlength="10" type="text" class="price_input" onkeypress='validate(event)' onkeyup='defaultPrice()' /><div style="float:right;margin-top:4px;">VNĐ</div>
                    </div>
                    
                    <div class="form_row">
                    <label class="contact"><strong>Đến :</strong></label>
                    <input value="<%=ViewData["price_to"] %>" id="price_to" name="price_to" maxlength="10" type="text" class="price_input" onkeypress='validate(event)' /><div style="float:right;margin-top:4px;">VNĐ</div>
                    </div>
                    
                    <div class="form_row"></div>
                    
                    <div class="form_row">
                    <label class="contact"><strong>Giá thuê từ :</strong></label>
                    <input value="<%=ViewData["price_rent_from"] %>" id="price_rent_from" name="price_rent_from" maxlength="10" type="text" class="price_input" onkeypress='validate(event)' onkeyup='defaultPriceRent()' /><div style="float:right;margin-top:4px;">VNĐ</div>
                    </div>
                    
                    <div class="form_row">
                    <label class="contact"><strong>Đến :</strong></label>
                    <input value="<%=ViewData["price_rent_to"] %>" id="price_rent_to" name="price_rent_to" maxlength="10" type="text" class="price_input" onkeypress='validate(event)' /><div style="float:right;margin-top:4px;">VNĐ</div>
                    </div>
                    
                    <div class="form_row">
                    <a href="javascript:;" onclick="checkSubmit()" class="contact" style="margin-right:110px;">Tìm</a>                    
                  </div> 
                 </form>  
                </div> 
                 
                 <% if ((string)ViewData["init"] != "noinit")
                    {%>
				 <div class="title" style="margin-top:30px;">
				    <span class="title_icon"><img src="/content/images/bullet3.gif" alt="" title=""></span>
				    Kết Quả <span class="form_row" style="font-size:12px;">- <%=ViewData["countBook"]%> sách được tìm thấy</span>
				  </div>
				  
				  
				<div class="new_products">
                     <% string[][] resultSearch = (string[][])ViewData["resultSearch"];
                        if (resultSearch[0] != null)
                        {
                            foreach (string[] row in resultSearch)
                            {
                                if (row == null) break;%>
                                <div class="new_prod_box">
                                    <a href="/book/detail?id=<%= row[6]%>"
                                                title="<div style='width:300px'>
					                            <div style='float:left;margin-left:5px;'>
						                            <center><img onerror=this.src='/content//content/images/no_image.jpg' width='98' height='140' src='<%= row[7]%>'></center>
					                            </div>
					                            <div style='float:left;margin-left:25px'>
					                                <div class='tt_name'>
						                                <%= row[1]%>
					                                </div>
					                                <div class='tt_detail'>
						                                <b>Mã Sách : </b><%= row[0]%> <br/><br/>
						                                <b>Tác Giả : </b><%= row[2]%> <br/><br/>
						                                <b>Giá Bán : </b><%= Html.Encode(row[3])%> <br/><br/>
						                                <b>Giá Thuê : </b><%= Html.Encode(row[4])%> <br/><br/>
						                                <b>Ngày Cập Nhật : </b><%= Html.Encode(row[8])%><br/><br/>
					                                </div>
					                            </div>
					                            <div style='clear:both;'></div>	
				                            </div>">
				                            <%= row[1]%>
				                      </a>
                                    <div class="new_prod_bg">
                                    <a href="/book/detail?id=<%= row[6]%>"><img onerror=this.src='/content//content/images/no_image.jpg' height="90" width="60" src="<%= row[7]%>"class="thumb" border="0" /></a>
                                    </div>           
                                </div>                    
                            <% }
                        }
                        else
                        { %>
                                <br />&nbsp;&nbsp;&nbsp;&nbsp;Hãy thử lại với từ khóa khác !    
                              <% }%>    
                              
                <div class="pagination">
                    <%= ViewData["pagination"]%>
                </div> 
            </div> 
            <%} %>
          </div>	
              

            

            
        <div class="clear"></div>
        <script type="text/javascript" src="/scripts/jquery.min.js"></script>
        <script type="text/javascript">
            function validate(evt) {
                var theEvent = evt || window.event;
                var key = theEvent.keyCode || theEvent.which;
                if (key != 8) {
                    key = String.fromCharCode(key); ;
                    var regex = /[0-9]/;
                    if (!regex.test(key)) {
                        theEvent.returnValue = true;
                        if (theEvent.preventDefault) theEvent.preventDefault();
                    }
                }
            }
            
            function defaultPrice() {
                $("#price_to").val($("#price_from").val());
            }

            function defaultPriceRent() {
                $("#price_rent_to").val($("#price_rent_from").val());
            }
            
            function checkSubmit() {
                if ($.trim($("#title").val()) == "")
                    alert("Vui lòng nhập từ khoá !");
                else if (parseInt($("#price_to").val()) < parseInt($("#price_from").val()))
                    alert("Giá mua đến phải lớn hơn hoặc bằng giá mua từ !");
                else if (parseInt($("#price_rent_to").val()) < parseInt($("#price_rent_from").val()))
                    alert("Giá thuê đến phải lớn hơn hoặc bằng giá thuê từ !");
                else $("#search").submit();
            }
        </script>
</asp:Content>

<asp:Content ID="indexContentRight" ContentPlaceHolderID="right_content" runat="server">
   <% Html.RenderAction("index","sidebar"); %>
</asp:Content>
